package com.hhb.config;

import com.hhb.web.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@ComponentScan(value = "com.hhb",includeFilters = {
        //springMVC只扫描Controller
        @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})
},useDefaultFilters = false)
@EnableWebMvc
public class ServletConfig implements WebMvcConfigurer {

    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        //静态资源
            //相当于开启<mvc:web-servlet-handle/>
        configurer.enable();
    }

    //配置视图解析器
    public void configureViewResolvers(ViewResolverRegistry registry) {
        //this.jsp("/WEB-INF/", ".jsp");
//        registry.jsp();
        registry.jsp("/WEB-INF/views/",".jsp");

    }

    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
    }



}
